//
//  FirstTableViewCell.m
//  时间
//
//  Created by cjy on 16/3/21.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "FirstTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "Model.h"

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
#define kSelfWidth self.frame.size.width
#define kSelfHeight self.frame.size.height
@implementation FirstTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    
    self.imglink = [[UIImageView alloc]init];

    [self.contentView addSubview:self.imglink];

       
        
    self.title  = [[UILabel alloc]init];
    
    [self.contentView addSubview:self.title];
        
        self.imglink.frame = CGRectMake(0, -(kHeight/1.7 -250)/2, kWidth, kHeight /1.7);
        
        
        _title.frame = CGRectMake(0, 250 / 2 - 30, kWidth, 30);
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        self.clipsToBounds = YES;
        
        self.imglink.contentMode = UIViewContentModeScaleAspectFill;
        
        
       
        
        _title.font = [UIFont boldSystemFontOfSize:16];
        
        _title.textAlignment = NSTextAlignmentCenter;
        
        _title.textColor = [UIColor whiteColor];
        

    }
    
    return self;

}



- (void)passModel:(Model *)model{

    [self.imglink sd_setImageWithURL:[NSURL URLWithString:model.imglink] placeholderImage:[UIImage imageNamed:@""]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.imglink.contentMode = UIViewContentModeScaleAspectFill;
    }];

    self.title.text = model.title;
    self.title.textAlignment = NSTextAlignmentCenter;
    self.title.textColor = [UIColor whiteColor];
    
}

- (CGFloat)cellOffset {
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
    CGFloat offset =  -offsetDig * (kHeight/1.7 - 250)/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    
    
    
    self.imglink.transform = transY;
    
    return offset;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
